home *** CD-ROM | disk | FTP | other *** search
/ Champak 25 / Volume 25 - JOGO DISK .iso / Games / elementalgame.swf / scripts / frame_5 / DoAction.as
Text File  |  2006-08-22  |  5KB  |  198 lines

  1. function moveHero()
  2. {
  3.    hitground = map_mc.hitTest(hero_mc._x,hero_mc._y,true);
  4.    hitroof = map_mc.hitTest(hero_mc._x,hero_mc._y - 30,true);
  5.    if(isAlive)
  6.    {
  7.       if(keyright)
  8.       {
  9.          hero_mc.gotoAndStop("runright");
  10.          hori = 5;
  11.       }
  12.       else if(_root.keyleft)
  13.       {
  14.          hero_mc.gotoAndStop("runleft");
  15.          hori = -5;
  16.       }
  17.       else if(hori > 0)
  18.       {
  19.          hori -= 1;
  20.       }
  21.       else if(hori < 0)
  22.       {
  23.          hori += 1;
  24.       }
  25.       else if(hori == 0)
  26.       {
  27.          hero_mc.gotoAndStop("stand");
  28.       }
  29.       if(keydown)
  30.       {
  31.          hero_mc.gotoAndStop("down");
  32.          hori = 0;
  33.       }
  34.    }
  35.    if(!hitground)
  36.    {
  37.       vert += 1;
  38.       if(vert > 0)
  39.       {
  40.          if(map_mc.hitTest(hero_mc._x,hero_mc._y + 2,true))
  41.          {
  42.             hero_mc._y += 2;
  43.             vert = 0;
  44.          }
  45.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y + 4,true))
  46.          {
  47.             hero_mc._y += 4;
  48.             vert = 0;
  49.          }
  50.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y + 6,true))
  51.          {
  52.             hero_mc._y += 6;
  53.             vert = 0;
  54.          }
  55.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y + 8,true))
  56.          {
  57.             hero_mc._y += 8;
  58.             vert = 0;
  59.          }
  60.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y + 10,true))
  61.          {
  62.             hero_mc._y += 10;
  63.             vert = 0;
  64.          }
  65.       }
  66.       else if(vert < 0 && isAlive)
  67.       {
  68.          if(map_mc.hitTest(hero_mc._x,hero_mc._y - 32,true))
  69.          {
  70.             hero_mc._y += 2;
  71.             vert = 0;
  72.          }
  73.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 34,true))
  74.          {
  75.             hero_mc._y += 4;
  76.             vert = 0;
  77.          }
  78.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 36,true))
  79.          {
  80.             hero_mc._y += 6;
  81.             vert = 0;
  82.          }
  83.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 38,true))
  84.          {
  85.             hero_mc._y += 8;
  86.             vert = 0;
  87.          }
  88.          else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 40,true))
  89.          {
  90.             hero_mc._y += 10;
  91.             vert = 0;
  92.          }
  93.       }
  94.    }
  95.    hitground = map_mc.hitTest(hero_mc._x,hero_mc._y,true);
  96.    if(hitground)
  97.    {
  98.       vert = 0;
  99.       if(keyspace && isAlive && !hitroof)
  100.       {
  101.          hero_mc.gotoAndStop("jump");
  102.          vert = -8;
  103.       }
  104.       if(map_mc.hitTest(hero_mc._x,hero_mc._y - 10,true))
  105.       {
  106.          hero_mc._y -= 10;
  107.       }
  108.       else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 8,true))
  109.       {
  110.          hero_mc._y -= 8;
  111.       }
  112.       else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 6,true))
  113.       {
  114.          hero_mc._y -= 6;
  115.       }
  116.       else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 4,true))
  117.       {
  118.          hero_mc._y -= 4;
  119.       }
  120.       else if(map_mc.hitTest(hero_mc._x,hero_mc._y - 2,true))
  121.       {
  122.          hero_mc._y -= 2;
  123.       }
  124.    }
  125.    hero_mc.oldx = hero_mc._x;
  126.    hero_mc._y += vert * msdiff;
  127.    hero_mc._x += hori * msdiff;
  128.    if(map_mc.hitTest(hero_mc._x + 4,hero_mc._y - 5,true))
  129.    {
  130.       hori -= 1;
  131.    }
  132.    if(map_mc.hitTest(hero_mc._x - 4,hero_mc._y - 5,true))
  133.    {
  134.       hori += 1;
  135.    }
  136.    if(map_mc.hitTest(hero_mc._x + hori,hero_mc._y - 20,true))
  137.    {
  138.       hero_mc._x += hero_mc.oldx - hero_mc._x;
  139.       hori = 0;
  140.       hero_mc.gotoAndStop(1);
  141.    }
  142. }
  143. function moveWorld()
  144. {
  145.    if(hero_mc._x > 500)
  146.    {
  147.       diff = 500 - hero_mc._x;
  148.       map_mc._x += diff;
  149.       details_mc._x += diff;
  150.       bullets._x += diff;
  151.       hero_mc._x += diff;
  152.    }
  153.    else if(hero_mc._x < 0)
  154.    {
  155.       diff = - hero_mc._x;
  156.       map_mc._x += diff;
  157.       details_mc._x += diff;
  158.       bullets._x += diff;
  159.       hero_mc._x += diff;
  160.    }
  161. }
  162. function killHero()
  163. {
  164. }
  165. stop();
  166. Stage.scaleMode = "noScale";
  167. Stage.showMenu = false;
  168. var now = getTimer();
  169. var then = now;
  170. var msdiff = 0;
  171. var points = 0;
  172. var xscale = hero_mc._xscale;
  173. var vert = 0;
  174. var hori = 0;
  175. var hitground = false;
  176. var hitroof = false;
  177. var isAlive = true;
  178. step1 = false;
  179. step2 = false;
  180. lives = 3;
  181. points = 0;
  182. _root.hero_mc._y = 280;
  183. _root.hero_mc._x = 50;
  184. _root.health_mc.gotoAndStop(1);
  185. _root.back.gotoAndPlay("end");
  186. onEnterFrame = function()
  187. {
  188.    then = now;
  189.    now = getTimer();
  190.    msdiff = (now - then) / 26;
  191.    keyleft = Key.isDown(37) || Key.isDown(65);
  192.    keyright = Key.isDown(39) || Key.isDown(68);
  193.    keyspace = Key.isDown(38) || Key.isDown(87) || Key.isDown(32);
  194.    keydown = Key.isDown(40) || Key.isDown(83);
  195.    moveHero();
  196.    moveWorld();
  197. };
  198.